
#include <iostream>
#include <assert.h>

using namespace std;

class Date
{
    friend ostream& operator<<(ostream& out, const Date& d);
    friend istream& operator>>(istream& in, Date& d);
public:
    
    Date(int year = 1, int month = 1, int day = 1)
        :_year(year)
         ,_month(month)
         ,_day(day)
    {}
    
    // 可以不写，默认生成的就够用
    Date(const Date& d)
    {
        _year = d._year;
        _month = d._month;
        _day = d._day;
    }

    ~Date()
    {
        _year = _month = _day = 0;
    }

    Date& operator=(const Date& d)
    {
        _year = d._year;
        _month = d._month;
        _day = d._day;

        return *this;
    }

    void Print()
    {
        cout << _year << ' ' << _month << ' ' << _day << endl;
    }

    int GetMonthDay(int year, int month)
    {
        static int Aday[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };

        if ((month == 2) && ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)))
        {
            return 29;
        }
        
        return Aday[month]; 
    }

    bool Check()
    {
        if (_year >= 1 && _month >= 1 && _month <= 12 && _day > 0 && _day <= GetMonthDay(_year, _month))
        {
            return true;
        }

        return false;
    }
    
	bool operator==(const Date& d) const;
	bool operator!=(const Date& d) const;

	bool operator>(const Date& d) const;
	bool operator>=(const Date& d) const;
	bool operator<(const Date& d) const;
	bool operator<=(const Date& d) const;

	Date operator+(int day) const;
	Date& operator+=(int day);
	Date operator-(int day) const;
	Date& operator-=(int day);
	Date& operator++(); // 前置++
	Date operator++(int); // 后置++
	Date& operator--(); // 前置++
	Date operator--(int); // 后置++

	int operator-(const Date& d) const; // 两个日期相差多少天

private:
    int _year;
    int _month;
    int _day;
};

inline ostream& operator<<(ostream& out, const Date& d)
{
    out << d._year << "年" << d._month << "月" << d._day << "日";

    return out;
}
inline istream& operator>>(istream& in, Date& d)
{
    in >> d._year >> d._month >> d._day;

    assert(d.Check());

    return in;
}
